package sun.sundy.functiontest;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import sun.sundy.functiontest.utils.ToastUtils;
import sun.sundy.functiontest.utils.permissions.Nammu;
import sun.sundy.functiontest.utils.permissions.PermissionCallback;
import sun.sundy.functiontest.utils.zxing.activity.CaptureActivity;

public class MainActivity extends AppCompatActivity {

    private final int SCAN_RESULT = 0x10;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if(Nammu.checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE))
        {
            ToastUtils.showLazzToast("dd");
        } else{
            if (Nammu.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
//            Snackbar.make(button, "Timber will need to read external storage to display songs on your device.",
//                    Snackbar.LENGTH_INDEFINITE)
//                    .setAction("OK", new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            Nammu.askForPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE, permissionReadstorageCallback);
//                        }
//                    }).show();
            } else {
                Nammu.askForPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE, permissionReadstorageCallback);
            }
        }

    }

    public void click(View view) {
//        SpeechSoundManager.getInstance().startSpeech("该包为混包");
        Bundle bundleClose = new Bundle();
        bundleClose.putString("mode", "0");
        startActivityForResult(new Intent(this, CaptureActivity.class).putExtras(bundleClose), SCAN_RESULT);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SCAN_RESULT) {
            if (data != null && data.getStringExtra("scan_result") != null) {
                String result = data.getStringExtra("scan_result");
                ToastUtils.showLazzToast(result);
            }
        }
    }


    final PermissionCallback permissionReadstorageCallback = new PermissionCallback() {
        @Override
        public void permissionGranted() {
//                loadEverything();
        }

        @Override
        public void permissionRefused() {
            finish();
        }
    };

}
